package edu.xidian.bdilab.jrbigdata.util;

import edu.xidian.bdilab.jrbigdata.controller.enterprise.RegisterController;
import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.domain.EnterpriseInfo;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import javax.management.StandardEmitterMBean;
import java.io.FileInputStream;
import java.io.InputStream;

@Controller
public class TransferExcelToMySQL {

    @Autowired
    RegisterController enterpriseRegisterController;

    public void transfer() throws Exception{
        //读excel
        InputStream is = new FileInputStream("D:\\研一\\金融大数据\\内资省局.xls");
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
        HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(0);
        for(int row =2;row <= hssfSheet.getLastRowNum();row++)
        {
            HSSFRow hssfRow = hssfSheet.getRow(row);
            if(hssfRow!=null){
                String socialCode = hssfRow.getCell(2).toString();
                String enterpriseName = hssfRow.getCell(0).toString();
                int registeredCaptial;
                if(hssfRow.getCell(8).toString().length()==0||hssfRow.getCell(8).toString()==null) {
                    registeredCaptial = 0;}
                else {
                    registeredCaptial = (int)Double.parseDouble(hssfRow.getCell(8).toString());
                }
                String ownerName = hssfRow.getCell(3).toString();
                int region = 5;
                String street = hssfRow.getCell(16).toString();
                String ownerPhone = hssfRow.getCell(17).toString();
                String contactName = hssfRow.getCell(3).toString();
                String contactPhone = hssfRow.getCell(17).toString();
                String establishTime = hssfRow.getCell(4).toString();
                String establishAddress = hssfRow.getCell(5).toString();
                String businessScop = hssfRow.getCell(14).toString();

                enterpriseRegisterController.register(socialCode,
                        enterpriseName,
                        registeredCaptial,
                        ownerName,
                        region,
                        street,
                        ownerPhone,
                        contactName,
                        contactPhone,
                        establishTime,
                        establishAddress,
                        "0",
                        "0",
                        businessScop,
                        "该企业暂无详情",
                        "123456");
            }
        }




    }
}
